const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const path = require('path')
const webpack = require('webpack')

module.exports = {
    // 入口文件
    entry: './src/main.js',
    // 出口文件
    output: {
        // 打包文件存放的绝对路径
        path: path.resolve(__dirname, 'dist'),
        // 打包文件名
        filename: 'bundle.js'
    },
    module: {
        rules: [
            // {
            //     test: /\.html$/,
            //     use: {
            //         loader: 'html-loader',
            //         options: {
            //             attrs: ['img:src','a:href']
            //         }
            //     }
            // },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env']
                    }
                }
            },
            {
                test: /\.js$/,
                use: 'eslint-loader',
                exclude: /node_modules/,
                enforce: 'pre'
            },
            {
                test: /\.vue$/,
                use: ['vue-loader']
            },
            {
                test: /\.css$/,
                use: ['style-loader','css-loader']
            },
            {
                test: /\.less$/,
                use: ['style-loader','css-loader','less-loader']
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        outputPath: 'img',
                        name: '[name].[ext]'
                    }
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            // title属性
            title: 'My Webpack Config',
            // 模板路径
            template: './public/index.html'
        }),
        new webpack.DefinePlugin({
            BASE_URL: JSON.stringify('./')
        }),
        new VueLoaderPlugin()
    ],
    optimization: {
        // 模块只导出被使用的成员
        usedExports: true,
        // 尽可能合并每一个模块到一个函数中
        concatenateModules: true,
        // 压缩输出结果
        // minimize: true
    }
    // resolve: {
    //     // extensions: ['.js','.vue'],
    //     alias: {
    //         'vue$': 'vue/dist/vue.esm.js',
    //         // '@': 'src'
    //     }
    // }
}